import request from '@/utils/request'

//  插入新的物料采购计划
export function insertPurchase(materialName, purchaseNum, partUsed, remark, departName) {
  return request({
    url: '/materialPurchase/purchase-information/insOne',
    method: 'post',
    params: {
      materialName: materialName,
      purchaseNum: purchaseNum,
      partUsed: partUsed,
      remark: remark,
      departName: departName, // 待修改
      preStatus: '计划中'
    }
  })
}

//  根据id对采购物料信息进行修改
export function updateMaterial(id, purchaseNum, partUsed, remark) {
  return request({
    url: '/materialPurchase/material-purchase/updMaterial',
    method: 'post',
    params: {
      id: id,
      purchaseNum: purchaseNum,
      partUsed: partUsed,
      remark: remark
    }
  })
}

//  初始化表格：根据 部门名称 查询所有状态为 计划中 的采购表
export function initTable(departName, currentPage, pageSize) {
  return request({
    url: '/materialPurchase/material-purchase/selAllMaterial',
    method: 'post',
    params: {
      preStatus: '计划中',
      departName: departName,
      currentPage: currentPage,
      pageSize: pageSize
    }
  })
}

//  根据id删除物料信息
export function deleteById(id) {
  return request({
    url: '/materialPurchase/material-purchase/delById',
    method: 'get',
    params: {
      id: id
    }
  })
}

//  将所有选中的物料 状态 修改为 审批中
export function updStatus(ids) {
  return request({
    url: '/materialPurchase/material-purchase/updStatus',
    method: 'post',
    params: {
      ids: ids,
      preStatus: '审批中'
    }
  })
}

//  分页 查询所有物料信息
export function selAllMaterial(curPage, pageSize) {
  return request({
    url: '/materialPurchase/material-purchase/selPageMateriInfo',
    method: 'post',
    params: {
      currentPage: curPage,
      pageSize: pageSize
    }
  })
}

// 查询所有 物料基本信息
export function selAllBaseInfo() {
  return request({
    url: '/materialPurchase/material-purchase/selectAll',
    method: 'get'
  })
}

//  查询截止日期
export function selDeadLine() {
  return request({
    url: '/materialPurchase/plan-deadline/selPlanDate',
    method: 'get'
  })
}

// 查询用户所属部门信息
export function selAccountDepart(name) {
  return request({
    url: '/materialPurchase/material-purchase/selAccount',
    method: 'post',
    params: {
      account: name
    }
  })
}
